﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

using HREDU;
using HREDU.Hoang_Tuan.Classes;

namespace HREDU.Hoang_Tuan
{
    public partial class frmQTCT : Form
    {
        //frmNHANSU frmParent;
        /// <summary>
        /// Id của nhân viên
        /// </summary>
        public int _ID_NHANVIEN;
        /// <summary>
        /// Cho biết có refresh lại datagrid hay không
        /// </summary>
        public bool _isRefresh = false;
        CCTQTCT objCTQTCT;

        public frmQTCT()
        {
            InitializeComponent();
        }

        public frmQTCT(int ID_NHANVIEN)
        {
            InitializeComponent();
            //frmParent = frm;
            _ID_NHANVIEN = ID_NHANVIEN;
        }

        public frmQTCT(int ID_NHANVIEN, int _id_ctqtct)
        {
            InitializeComponent();
            //frmParent = frm;
            _ID_NHANVIEN = ID_NHANVIEN;
            objCTQTCT = CCTQTCTCollection.LayObjectTheoID(_id_ctqtct);
        }

        private void frmQTCT_Load(object sender, EventArgs e)
        {
            if (objCTQTCT != null)
            {
                txtNoiDung.Text = objCTQTCT.NOIDUNG;
                txtTuNam.Text = objCTQTCT.TUNAM;
                txtDenNam.Text = objCTQTCT.DENNAM;
            }
            else
                objCTQTCT = new CCTQTCT();
        }

        private void btnGhi_Click(object sender, EventArgs e)
        {
            objCTQTCT.ID_NHANVIEN = _ID_NHANVIEN;
            objCTQTCT.TUNAM = txtTuNam.Text;
            objCTQTCT.DENNAM = txtDenNam.Text;
            objCTQTCT.NOIDUNG = txtNoiDung.Text;
            
            if (objCTQTCT.ID_CTQTCT > 0)
            {
                if (CCTQTCTCollection.Update(objCTQTCT) > 0)
                    MessageBox.Show("Cập nhật thành công.");
            }
            else
            {
                if (CCTQTCTCollection.Insert(objCTQTCT) > 0)
                    MessageBox.Show("Thêm thành công.");
            }
            //frmParent.LoadDataGridJanusQTCT();
            _isRefresh = true;
            
        }

        private void btnHuy_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}